home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / Selection.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  5.4 KB  |  202 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Selection.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      1/4/94    EZ        clean up
  13.          <1>      1/4/94    EZ        first checked in
  14.  
  15. */
  16.  
  17. #ifndef _Selection_
  18. #define _Selection_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _TextensionCommon_
  25. #include "TextensionCommon.h"
  26. #endif
  27.  
  28. #ifndef _RunObject_
  29. #include "RunObject.h"
  30. #endif
  31. //***************************************************************************************************
  32.  
  33. //constants and types for ClickLoop message
  34. const ushort kAutoScroll = 1;
  35.  
  36. typedef void (*ClickLoopProcPtr)(unsigned short message, void* data, void* refCon);
  37.  
  38.  
  39. //***************************************************************************************************
  40.  
  41. inline void InitSelection() {}
  42. inline void EndSelection() {}
  43. //***************************************************************************************************
  44.  
  45. #ifdef __SC__
  46. class __machdl CTextension; //later
  47. class __machdl CTextensionDisplay; //later
  48. #else
  49. class CTextension; //later
  50. class CTextensionDisplay; //later
  51. #endif
  52.  
  53. class    CSelection    :    public HandleObject {
  54. public:
  55. //-----
  56.     CSelection();
  57.     
  58.     void ISelection();
  59.     
  60.     void SetHandlers(CTextension* textension, CTextensionDisplay* display);
  61.     
  62.     virtual void Free();
  63.     
  64.     #ifdef txtnNever
  65.     virtual CSelection* CreateEmptyClone();
  66.     #endif
  67.     
  68.     inline void SetAutoScroll(Boolean flag) {fAutoScroll = flag;}
  69.     
  70.     Boolean Click(const EventRecord* event, TClickCommandInfo* clickCommandInfo
  71.                                 , ClickLoopProcPtr clickProc = nil, void* clickProcData = nil);
  72.     
  73.     void ArrowKey(unsigned char key, long modifiers);
  74.     
  75.     void Activate(Boolean activ, Boolean turnSelOn =true);
  76.     
  77.     Boolean Idle();
  78.     unsigned long GetIdleTime(); //Idle should be called after the returned value (in Ticks)
  79.     
  80.     Boolean SetCursor(Point mousePt);
  81.     /*returns false if the cursor is outside textension area
  82.     */
  83.     
  84.     void Draw();
  85.     inline void DisableDrawing() {--fSelectionVisLevel;}
  86.     inline void EnableDrawing() {++fSelectionVisLevel;}
  87.     inline Boolean IsDrawEnabled() {return fSelectionVisLevel >= 0;}
  88.     
  89.     void SetDrawInactivSelStat(Boolean drawIt);
  90.     inline Boolean GetDrawInactivSelStat() {return fDrawInactivSel;}
  91.     
  92.     void Invalid(Boolean turnSelOff = false);
  93.     
  94.     void SetSelStat(char newSelStat);
  95.     inline char GetSelStat() const {return fSelStat;}
  96.     
  97.     void GetSelectionRange(TOffsetRange* selRange) const;
  98.     
  99.     Boolean SetSelectionRange(const TOffsetRange& selRange, Boolean forceOn = false);
  100.     
  101.     void ExtendSelection(TOffsetRange extRange);
  102.  
  103.     void AdjustCharOffset(TOffset* charOffset);
  104.     
  105.     #ifdef txtnNever
  106.     void SetCaretDirection(const CRunObject* caretRun);
  107.     #endif
  108.     
  109.     void DelayCaret();
  110.     
  111.     void GetCaretRect(TxtnLongRect* caretRect); //in abs coord
  112.     
  113.     void GetRangePosition(TOffsetRange theRange, RunPositionPB* positionPb);
  114.     
  115. protected:
  116. //--------
  117.     CTextension*    fTextension;
  118.     CTextensionDisplay* fDisplay;
  119.     
  120.     virtual void DoClickLoop(ushort message, void* data);
  121.         
  122. private:
  123. //------
  124. long fClickTime;
  125. Point fClickPoint;
  126. char fCountClick;
  127. Boolean fAutoScroll;
  128.  
  129. char fSelStat;
  130. Boolean fDrawn;
  131. /*useful in many cases, most important when calling "SetSelStat" without Drawing the
  132. inactiv initialized value of  "fSelStat". In this case "SetSelStat" can not know whether the old
  133. selStat was shown or not (to blank it before drawing the new one)*/
  134.  
  135. long fCaretTime;
  136.  
  137. char fCaretDir;
  138. Boolean fUserCaret;
  139. //I believe, The caret shouldn't change position with keyboard script changes if the user has chosen this caret position
  140.  
  141. Boolean fDrawInactivSel;
  142.  
  143. TxtnLongRect fCaretRect; //fCaretRect.top < 0 ==> caret rect is not valid
  144.  
  145. #ifdef txtnMultiFrames
  146. long fCaretFrame;
  147. #endif
  148.  
  149. TOffsetRange fSelRange;
  150.  
  151. long fUpDownArrowsPix;
  152.  
  153. static long fOSCaretTime;
  154. static RgnHandle fSelectRgn;
  155. static char fSelectionVisLevel;
  156. /*
  157. declared global when foot notes have been implemented, in this case user may want to hide draw
  158. across calls which may change the context (and thus the Selection)
  159. */
  160. //---------------------------------------------------    
  161.     
  162.     
  163.     Boolean GetClickRange(TOffsetRange* clickRange, short countClicks =0);
  164.     
  165.     Boolean CalcClickPoint(long scrollTicks, LongPoint* scrollVals);
  166.     
  167.     void SetSelStart(TOffset newSelStart);
  168.     void SetSelEnd(TOffset newSelEnd);
  169.     void DragSelection(TOffsetRange centerRange, ClickLoopProcPtr clickProc = nil, void* clickProcData = nil);
  170.     
  171.     void DrawInactivSelection(const Rect* selRect = nil) const;
  172.     //if selRect is nil, select fSelectRgn
  173.     
  174.     void PreSelection() const;
  175.     
  176.     void PostSelection() const;
  177.     
  178.     void SelectRange(TOffsetRange range2Select, char caretDir);
  179.  
  180.     void SelectFrame(long frameNo, TOffsetRange range2Select
  181.                                         , long firstLine, long lastLine, char caretDir) const;
  182.     void SelectLine(long lineNo, long frameNo, TOffsetRange range2Select
  183.                                     , char caretDir, TxtnLongRect* lineRect) const;
  184.     void SelectRect(const TxtnLongRect* theRect, long frameNo
  185.                                     , Boolean useHilitColor = true, Boolean add2SelectRgn = true) const;
  186.     
  187.     void CalcRangeRect(TOffsetRange theRange, TxtnLongRect* absRect, Boolean lineBounds =true);
  188.     //theRange is nil ==> cuurent sel range
  189.     
  190.     void CalcCaretRect();
  191.  
  192.     void SelectCaret();
  193.     
  194.     char GetCaretDirection() const;
  195.         
  196.     CRunObject* IsCustomSelection(const TOffsetRange* charRange =nil);
  197.     CRunObject* IsPointInActivGraphics(Point thePt, const TOffsetRange& pointRange, RunPositionPB* posPb);
  198. };
  199. //*************************************************************************************************
  200.  
  201. #endif
  202.